package com.java.config;

import org.apache.spark.sql.SparkSession;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

/**
 * @Author: ZhangJin
 * @Date: 2020/9/10 14:10
 */

@Configuration
public class ApplicationConfig {

    @Value("${app.name}")
    private String appName;

    @Value("${master.uri}")
    private String masterUri;

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getMasterUri() {
        return masterUri;
    }

    public void setMasterUri(String masterUri) {
        this.masterUri = masterUri;
    }

    @Bean
    public SparkSession sparkSession(){
        return SparkSession
                .builder()
                .appName(appName)
                .master(masterUri)
                .config("spark.sql.parquet.binaryAsString", "true")
//                .config("spark.driver.host","DESKTOP-PCCV4OO")
                .enableHiveSupport()
                .getOrCreate();
    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(){
        return new PropertySourcesPlaceholderConfigurer();
    }

}
